package com.xbongbong.saas.model;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.wrap.IModel;
import com.xbongbong.pro.businessdata.pojo.dto.FormatExplainDTO;
import com.xbongbong.pro.domain.entity.UpdateDataEntity;
import com.xbongbong.pro.formdata.pojo.dto.SaasAnalysisDataDTO;
import com.xbongbong.saas.domain.entity.QuotationProductEntity;
import com.xbongbong.saas.domain.entity.ext.ProductEntityExt;
import com.xbongbong.saas.domain.entity.ext.QuotationEntityExt;
import com.xbongbong.saas.enums.UpdateDataTypeEnum;
import com.xbongbong.saas.enums.business.QuotationEnum;
import org.apache.poi.ss.formula.functions.T;
import org.elasticsearch.action.support.WriteRequest;

import java.util.List;
import java.util.Map;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/8/12 17:21
 * @since v1.0
 */
public interface QuotationModel extends IModel<QuotationEntityExt> {

    /**
     * 根据参数获取合同集合
     *
     * @param param 参数
     * @author long.rao
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.QuotationEntityExt>
     * @date 2019-08-12 17:22
     */
    @Override
    List<QuotationEntityExt> findEntitys(Map<String, Object> param);

    /**
     * 报价单数据单条查询
     *
     * @param key    主键ID
     * @param corpid 公司ID
     * @return Integer
     * @author long.rao
     * @date 2019-08-12 19:47
     */
    QuotationEntityExt getByKey(Long key, String corpid);

    /**
     * 单个删除
     * @param id
     * @param corpid
     * @return
     * @throws XbbException
     */
    Integer deleteByKey(Long id,String corpid) throws XbbException;
    /**
     * 批量删除
     * @author long.rao
     * @date 2019-08-16 20:27
     * @param deleteIdIn
     * @param corpid
     * @return java.lang.Integer
     * @throws XbbException 业务异常
     */
    Integer deleteBatch(List<Long> deleteIdIn, String corpid) throws XbbException;

    /**
     * Description: 根据到期时间获取报价单（除去在  工作流  中的）
     * @param corpid 公司id
     * @param startDeadlineTime 到期时间  开始
     * @param endDeadlineTime 到期时间  结束
     * @return java.util.List<com.xbongbong.saas.domain.entity.ext.QuotationEntityExt>
     * @author 刘阳
     * @date 2019/9/10 11:02 AM
     * @since v1.0
     */
    List<QuotationEntityExt> getQuotationByDeadlineTime(String corpid, Long startDeadlineTime, Long endDeadlineTime);

    /**
     * 批量编辑
     * @author long.rao
     * @date 2019-09-10 15:51
     * @param updateList 更新数据
     * @param corpid 公司id
     * @return
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid) throws XbbException;

    /**
     * 数据还原
     * @author xingxing.xiao
     */
    Integer restoreBatch(List<Long> dataIdList, String corpid, Integer del) throws XbbException;
    /**
     * 批量编辑
     * @author 吴峰
     * @date 2020/6/15 11:04
     * @param updateList 更新数据
     * @param corpid 公司id
     * @return
     * @throws XbbException 业务异常
     */
    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid, WriteRequest.RefreshPolicy refreshPolicy) throws XbbException;

    Integer updateBatch(List<UpdateDataEntity> updateList, String corpid,boolean needThrow) throws XbbException;

    @Override
    List<QuotationEntityExt> findEntitysWithoutSub(Map<String, Object> param);

    /**
     * 编辑时格式化解释
     *
     * @param formatExplainDTO 入参
     * @throws XbbException 异常
     * @author long.rao
     * @date 2019-08-16 11:10
     */
    void formatUpdateExplain(FormatExplainDTO formatExplainDTO) throws XbbException;

    /**
     * 编辑时将获取数据格式化
     *
     * @param formDataUpdateGetDTO saas编辑数据
     * @param result               要返回的jsonobject
     * @throws XbbException 业务异常
     * @author long.rao
     * @date 2019-08-12 19:58
     */
    void formatData(SaasAnalysisDataDTO formDataUpdateGetDTO, JSONObject result) throws XbbException;

    void getProductList(String corpid, List<QuotationProductEntity> quoProductList, JSONArray productArray, Map<Long, ProductEntityExt> productMap) throws XbbException;

    JSONObject formatSingleProduct(QuotationProductEntity quotationProductEntity);

    void formatProduct4Show2(Long dataId, String corpid, JSONObject data, UpdateDataTypeEnum updateDataTypeEnum) throws XbbException;

    void formatProduct4Show3(List<QuotationProductEntity> quotationProductEntityList, JSONObject productData, UpdateDataTypeEnum updateDataTypeEnum, String corpid) throws XbbException;

    Integer updateTime(Long id,String corpid) throws XbbException ;

    /**
     * 根据指定字段获取最新版本报价单
     * @param corpid
     * @param dataId
     * @param quotationEnum
     * @param clazz
     * @return java.util.List<T>
     * @author 吴峰
     * @date 2022/2/16 17:00
     * @throws XbbException
     */
    <T> List<T> getQuotationListByLinkId(String corpid, Long dataId, QuotationEnum quotationEnum, Class<T> clazz) throws XbbException;
}
